package com.csiec.clock.bean;

import android.annotation.SuppressLint;
import android.util.Log;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyClock implements Serializable {
    private String id;
    private String name;
    private String sId;
    private String type;
    private String singleStartTime;
    private String singleEndTime;
    private String manyStartDate;
    private String manyEndDate;
    private String manyStartTime;
    private String manyEndTime;
    private String positionType;
    private String positionInformation;
    private String positionRange;
    private String informationRequired;
    private String informationType;
    private String sharingCode;

    public static final String CLOCKTYPE = "单次打卡";

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getsId() {
        return sId;
    }

    public void setsId(String sId) {
        this.sId = sId;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getSingleStartTime() {
        return singleStartTime;
    }

    public void setSingleStartTime(String singleStartTime) {
        this.singleStartTime = singleStartTime;
    }

    public String getSingleEndTime() {
        return singleEndTime;
    }

    public void setSingleEndTime(String singleEndTime) {
        this.singleEndTime = singleEndTime;
    }

    public String getManyStartDate() {
        return manyStartDate;
    }

    public void setManyStartDate(String manyStartDate) {
        this.manyStartDate = manyStartDate;
    }

    public String getManyEndDate() {
        return manyEndDate;
    }

    public void setManyEndDate(String manyEndDate) {
        this.manyEndDate = manyEndDate;
    }

    public String getManyStartTime() {
        return manyStartTime;
    }

    public void setManyStartTime(String manyStartTime) {
        this.manyStartTime = manyStartTime;
    }

    public String getManyEndTime() {
        return manyEndTime;
    }

    public void setManyEndTime(String manyEndTime) {
        this.manyEndTime = manyEndTime;
    }

    public String getPositionType() {
        return positionType;
    }

    public void setPositionType(String positionType) {
        this.positionType = positionType;
    }

    public String getPositionInformation() {
        return positionInformation;
    }

    public void setPositionInformation(String positionInformation) {
        this.positionInformation = positionInformation;
    }

    public String getPositionRange() {
        return positionRange;
    }

    public void setPositionRange(String positionRange) {
        this.positionRange = positionRange;
    }

    public String getInformationRequired() {
        return informationRequired;
    }

    public void setInformationRequired(String informationRequired) {
        this.informationRequired = informationRequired;
    }

    public String getInformationType() {
        return informationType;
    }

    public void setInformationType(String informationType) {
        this.informationType = informationType;
    }

    public String getSharingCode() {
        return sharingCode;
    }

    public void setSharingCode(String sharingCode) {
        this.sharingCode = sharingCode;
    }

    public static String getCLOCKTYPE() {
        return CLOCKTYPE;
    }

    public String getSingleTime() {
        //单次打卡
        if (CLOCKTYPE.equals(type)) {
            return singleStartTime + " 至 " + singleEndTime;
        } else {
            //多次打卡
            return manyStartDate + " " + manyStartTime + " 至 " + manyEndDate + " " + manyEndTime;
        }
    }

    public int getState() {

        Date dateStart = null;
        Date dateEnd = null;
        Date nowDate = new Date();
        @SuppressLint("SimpleDateFormat") SimpleDateFormat singleFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        @SuppressLint("SimpleDateFormat") SimpleDateFormat manyFormatter = new SimpleDateFormat("yyyy-MM-dd");

        try {
            //单次打卡
            if (CLOCKTYPE.equals(type)) {
                dateStart = singleFormatter.parse(singleStartTime + " " + manyStartTime);
                dateEnd = singleFormatter.parse(singleEndTime + " " + manyEndTime);
            } else {
                //多次打卡
                dateStart = singleFormatter.parse(manyStartDate + " " + manyStartTime);
                dateEnd = singleFormatter.parse(manyEndDate + " " + manyEndTime);
            }
        } catch (Exception e) {
            Log.d("TAG", "getState: 时间错误");
        }

        assert dateEnd != null;
        assert dateStart != null;
        if (dateStart.after(nowDate)) {
            return 2;
        } else if (dateEnd.before(nowDate)) {
            return 1;
        } else {
            return 0;
        }

    }

    @Override
    public String toString() {
        return "MyClock{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sId='" + sId + '\'' +
                ", type='" + type + '\'' +
                ", singleStartTime='" + singleStartTime + '\'' +
                ", singleEndTime='" + singleEndTime + '\'' +
                ", manyStartDate='" + manyStartDate + '\'' +
                ", manyEndDate='" + manyEndDate + '\'' +
                ", manyStartTime='" + manyStartTime + '\'' +
                ", manyEndTime='" + manyEndTime + '\'' +
                ", positionType='" + positionType + '\'' +
                ", positionInformation='" + positionInformation + '\'' +
                ", positionRange='" + positionRange + '\'' +
                ", informationRequired='" + informationRequired + '\'' +
                ", informationType='" + informationType + '\'' +
                ", sharingCode='" + sharingCode + '\'' +
                '}';
    }
}
